package com.pengji.rcp.plugin.table;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import com.pengji.rcp.plugin.domain.TestTable;

public class InsertTable {
	private static InputStream is;
	private static Workbook workBook;
	private static Sheet sheet;

	public static void main(String[] args) {
		instrnTable();
	}

	static void instrnTable() {
		try {
			File file = new File("d:/1.xls");
			is = new FileInputStream(file);
			workBook = Workbook.getWorkbook(is);
		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		sheet = workBook.getSheet(0);

		//sheet.getRows()
		List<TestTable> listTestTables = new ArrayList<TestTable>();
		for (int i = 3; i < sheet.getRows(); i++) {
			List<String> listString = new ArrayList<String>();
			for (int j = 0; j < sheet.getColumns(); j++) {
				listString.add(sheet.getCell(j, i).getContents());
			}
			TestTable testTable = new TestTable();
			testTable.setString1(listString.get(0));
			testTable.setString2(listString.get(1));
			testTable.setString3(listString.get(2));
			testTable.setString4(listString.get(3));
			testTable.setString5(listString.get(4));
			testTable.setString6(listString.get(5));
			testTable.setString7(listString.get(6));
			testTable.setString8(listString.get(7));
			testTable.setString9(listString.get(8));
			testTable.setString10(listString.get(9));
			testTable.setString11(listString.get(10));
			testTable.setString12(listString.get(11));
			testTable.setString13(listString.get(12));
			testTable.setString14(listString.get(13));
			testTable.setString15(listString.get(14));
			testTable.setString16(listString.get(15));
			testTable.setString17(listString.get(16));
			listTestTables.add(testTable);
		}
		HibernateTest.addTableTest1(listTestTables);

		//System.out.println(listTestTables.size());
	}
}
